package demo1;

/**
 * @Author liangzai
 * @Description:
 */
public class Training {
    //消失的两个数字
    public int[] missingTwo(int[] nums) {
        int n = nums.length+2;
        int tmp = 0;
        for(int i = 0;i<nums.length;i++){
            tmp ^= nums[i];
        }
        for(int i = 1;i<=n;i++){
            tmp ^= i;
        }
        int diff = 0;
        while (true) {
            if(((tmp>>diff) & 1) == 1) break;
            else diff++;
        }
        int[] ret = new int[2];
        for (int i = 1; i <= n; i++) {
            if(((i>>diff)&1)==0) ret[0] ^= i;
        }
        for(int x:nums){
            if(((x>>diff)&1)==0) ret[0] ^= x;
        }
        ret[1] = ret[0]&tmp;
        return ret;
    }

    //只出现一次的数字二
    public int singleNumber(int[] nums) {
        int ret = 0;
        for (int i = 0; i < 32; i++) {
            int sum = 0;
            for(int num:nums){
                if (((num >> i) & 1) == 1) {
                    sum++;
                }
            }
            sum%=3;
            if(sum==1) ret |= (1<<i);
        }
        return ret;
    }

    //求出硬币游戏的赢家
    public String losingPlayer(int x, int y) {
        if( x*4 < y ){
            if(x%2==0) return "Bob";
            else return "Alice";
        }else{
            if((y/4)%2==0) return "Bob";
            else return "Alice";
        }
    }

    //两整数之和
    public int getSum(int a, int b) {
        //int n = a;int m = b;
        int n = 0;int m = 0;
        while (true) {
            n = a^b;
            m = (a&b)<<1;
            a = n;
            b = m;
            if(m==0) break;
        }
        return n;
    }

    //丢失的数字
    public int missingNumber(int[] nums) {
        int ret = 0;
        int n = nums.length;
        for (int i = 0; i <= nums.length; i++) {
            ret &= i;
        }
        for (int i = 0; i < n; i++) {
            ret &= nums[i];
        }
        return ret;
    }

    public static void main1(String[] args) {
        int a = 'a';
        System.out.println(a);
    }

    //判断字符是否唯一
    public boolean isUnique(String astr) {
        int n = astr.length();
        if(n>26) return false;
        int a = 0;
        for (int i = 0; i < n; i++) {
            char ch = astr.charAt(i);
            int index = Integer.valueOf(ch)-97;
            int b = 1<<index;
            if ((a & b) == b) return false;
            else {
                a |= b;
            }
        }
        return true;
    }
}
